      SUBROUTINE TAVISPAK3X(EA,FCN,A,B,C,LUERR,IERR)
      IMPLICIT REAL*8 (A-H,O-Z)
C
C THIS ROUTINE SOLVES FOR THE A,B,C COEFFICIENTS OF THE FUNCTION
C
C        FCN = A*COS(EA) + B*SIN(EA) - C
C
C WHICH IS USED TO APPROXIMATE THE RAM AND SHADOW FUNCTIONS. THREE
C PAIRS OF ECCENTRIC ANOMALY AND FUNCTION VALUES ARE INPUT AND THE
C CURVE PASSES THROUGH THEM.
C
C VARIABLE DIM TYPE I/O DESCRIPTION
C -------- --- ---- --- -----------
C
C EA        3   R*8  I  EA(I) IS THE ECCENTRIC ANOMALY VALUE ASSOCIATED
C                       WITH THE RAM OR SHADOW FUNCTION VALUE FCN(I).
C
C FCN       3   R*8  I  FCN(I) IS THE RAM OR SHADOW FUNCTION VALUE. THE
C                       THREE (EA(I),FCN(I)) PAIRS ARE USED TO DEFINE
C                       THE  A*COS(EA) + B*SIN(EA) - C  CURVE.
C
C A         1   R*8  O  THE 'A' COEFFICIENT IN THE EXPRESSION
C
C B         1   R*8  O  THE 'B' COEFFICIENT IN THE EXPRESSION
C
C C         1   R*8  O  THE 'C' COEFFICIENT IN THE EXPRESSION
C
C IERR      1   I*4  O  = 0, NO ERRORS.
C                       = OTHERWISE, NUMERICAL ERROR. NO A,B,C RETURNED.
C
C***********************************************************************
C
C CODED BY C PETRUZZO GSFC/742 1/86
C    MODIFIED....
C
C***********************************************************************
C
      REAL*8 EA(3),FCN(3)
      REAL*8 A13/-1.D0/, A23/-1.D0/, A33/-1.D0/
      REAL*8 DEGRAD / 57.29577951308232D0 /
C
      DET(A11,A21,A31,A12,A22,A32) =
     *   A11*A22*A33 + A12*A23*A31 + A13*A21*A32
     *  -A31*A22*A13 - A21*A12*A33 - A11*A32*A23
C
      IBUG = 0
      LUBUG = 19
C
      IF(IBUG.NE.0) WRITE(LUBUG,8501) (EA(I)*DEGRAD,I=1,3),FCN
 8501 FORMAT(' TAVISPAK3X DEBUG. INPUT='/,
     *       '        EA=',3G16.8/,
     *       '       FCN=',3G16.8)
C
C THE SHADOW OR RAM FUNCTION DEFINES WHEN A TARGET SATISFIES THE
C AVAILABILITY REQUIREMENT.  WHEN THE FUNCTION IS POSITIVE, IT IS
C AVAILABLE.  WHEN NEGATIVE, IT IS NOT AVAILABLE.  WE APPROXIMATE THE
C FUNCTION BY  FCN = A*COS(EA) + B*SIN(EA) - C.  WE HAVE THREE (EA,FCN)
C PAIRS, SO WE CAN SOLVE FOR A, B, AND C.
C
C
C INITIALIZE
C
      IERR = 0
      COS1 = DCOS(EA(1))
      COS2 = DCOS(EA(2))
      COS3 = DCOS(EA(3))
      SIN1 = DSIN(EA(1))
      SIN2 = DSIN(EA(2))
      SIN3 = DSIN(EA(3))
C
C SOLVE FOR THE A, B, AND C CONSTANTS.
C
      D =  DET( COS1,   COS2,   COS3,   SIN1,   SIN2,   SIN3 )
      IF(DABS(D).LT.1.D-15) THEN
        IERR = 9
        IF(IBUG.NE.0) WRITE(LUBUG,8607) D
 8607   FORMAT(/,' TAVISPAK3X. BAD D-VALUE. VALUE=',G23.16)
        GO TO 9999
        END IF
      AN = DET( FCN(1), FCN(2), FCN(3), SIN1,   SIN2,   SIN3 )
      BN = DET( COS1,   COS2,   COS3,   FCN(1), FCN(2), FCN(3) )
      A = AN/D
      B = BN/D
      C = A * COS1  +  B * SIN1  -  FCN(1)
      IF(IBUG.NE.0) THEN
        TEST1 = A*COS1 + B*SIN1 - C - FCN(1)
        TEST2 = A*COS2 + B*SIN2 - C - FCN(2)
        TEST3 = A*COS3 + B*SIN3 - C - FCN(3)
        WRITE(LUBUG,8602) D,AN,BN,A,B,C,TEST1,TEST2,TEST3
 8602   FORMAT(' TAVISPAK3X DEBUG 8602.'/,
     *       '    D,AN,BN=',3G16.8/,
     *       '    A,B,C=  ',3G16.8/,
     *       '    TEST1,TEST2,TEST3=',3G16.8)
        END IF
C
      IF(IBUG.NE.0) WRITE(LUBUG,8606) A,B,C
 8606 FORMAT(' TAVISPAK3X RETURNING.  A,B,C=',3G15.7)
C
 9999 CONTINUE
      RETURN
      END
